package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.dto.SSHManageDTO;
import cn.tpshion.devops.domain.entity.SSHManage;
import cn.tpshion.devops.domain.entity.SSHSecretData;
import cn.tpshion.devops.service.WebSSHService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/sshManage")
public class SSHManageController {

    @Resource
    private WebSSHService webSSHService;

    @PostMapping("/list")
    public Result<List<SSHManage>> list(){
        return Result.ok(webSSHService.list());
    }

    @PostMapping("/add")
    public Result add(@Valid @RequestBody SSHManage sshManage){
        webSSHService.add(sshManage);
        return Result.ok();
    }

    @PostMapping("/delete")
    public Result delete(@Valid @RequestBody SSHManageDTO dto){
        webSSHService.delete(dto);
        return Result.ok();
    }

    @PostMapping("/testConn")
    public Result testConn(@Valid @RequestBody SSHSecretData sshSecretData){
        webSSHService.testConn(sshSecretData);
        return Result.ok();
    }
}
